using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Pronghorn.Core;

namespace TestDoubles
{

	public enum StubControllerContextTypes
	{
		Home,
		Scripts,
		Actions
	}


	public class StubControllerContext : ControllerContext, IProngHornControllerContext
	{

		private RouteData _routeData = new RouteData();

		protected StubControllerContext()
		{
		}

		public new ProngHornControllerBase Controller { get; set; }

		public override HttpContextBase HttpContext { get; set; }

		public new RequestContext RequestContext { get; set; }

		public override RouteData RouteData
		{
			get { return _routeData; }
			set { _routeData = value; }
		}

		public ISiteContext SiteContext { get; set; }

		public static IProngHornControllerContext CreateContext(StubControllerContextTypes type)
		{
			var context = new StubControllerContext();
			switch (type)
			{
				case StubControllerContextTypes.Actions:
					context.RouteData.Route = new Route("{controller}/{action}", context.RouteData.RouteHandler);
					context.RouteData.Values.Add("Controller", "Home");
					context.RouteData.Values.Add("Action", "Index");
					context.SiteContext = getSiteContext();
					context.HttpContext = getHttpContext();

					break;
				case StubControllerContextTypes.Home:

					context.RouteData.Route = new Route("{controller}/{action}", context.RouteData.RouteHandler);
					context.RouteData.Values.Add("Controller", "Home");
					context.RouteData.Values.Add("Action", "Index");
					context.SiteContext = getSiteContext();

					break;
				case StubControllerContextTypes.Scripts:

					context.RouteData.Route = new Route("{controller}/{action}", context.RouteData.RouteHandler);
					context.RouteData.Values.Add("Controller", "scripts");
					context.RouteData.Values.Add("Action", "js");
					context.SiteContext = getSiteContext();

					break;
			}
			return context;
		}

		private static HttpContextBase getHttpContext()
		{
			return new StubHttpContextBase();
		}

		private static SiteContext getSiteContext()
		{
			return new SiteContext
						{
						SkinPath = "pc/Skins",
						CssVersion = "V01",
						Theme = "Default"
						};
		}
	}

	public class StubHttpContextBase : HttpContextBase
	{
		public override HttpResponseBase Response
		{
			get
			{
				return new StubHttpResponseBase();
			}
		}
	}

	public class StubHttpResponseBase : HttpResponseBase
	{
		private string _contentType;

		public override string ContentType
		{
			get
			{
				return _contentType;
			}
			set
			{
				_contentType = value;
			}
		}

		public override void Write(string s)
		{
			
		}
	}
}